#include <Windows.h>
#include <gl/GL.h>

HWND hWindow;
HMENU hMenu;

char szClassName[] = "WindowsApp";
char szClientName[] = "Document";

LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

bool RegisterClass(HINSTANCE hInstance)
{
	WNDCLASSEX wincl;
	wincl.hInstance = hInstance;
	wincl.lpszClassName = szClassName;
	wincl.lpfnWndProc = WindowProcedure;
	wincl.style = CS_DBLCLKS;
	wincl.cbSize = sizeof(WNDCLASSEX);
	
	
	wincl.hIcon = LoadIcon(NULL, IDI_APPLICATION); //LoadIcon (GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON));
	wincl.hIconSm = LoadIcon(NULL, IDI_APPLICATION);//LoadIcon (GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON));
	wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
	wincl.lpszMenuName = NULL;//MAKEINTRESOURCE(IDR_MAIN);
	wincl.cbClsExtra = 0;
	wincl.cbWndExtra = 0;
	wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

	return RegisterClassEx (&wincl);
}

int WINAPI WinMain_Dummy(HINSTANCE hThisInstance, HINSTANCE hPrevInstance,
	LPSTR lpszArgument, int nFunsterStil)
{
	MSG messages;

	if (!RegisterClass(hThisInstance))
		return 0;

	hWindow = CreateWindowEx(
			0,					/* Extended possibilites for variation */
			szClassName,		/* Classname */
			"OpenGL Shader Test",			/* Title Text */
			WS_OVERLAPPEDWINDOW,/* default window */
			CW_USEDEFAULT,		/* Windows decides the position */
			CW_USEDEFAULT,		/* where the window ends up on the screen */
			800,				/* The programs width */
			600,				/* and height in pixels */
			HWND_DESKTOP,		/* The window is a child-window to desktop */
			NULL,				/* No menu */
			hThisInstance,		/* Program Instance handler */
			NULL				/* No Window Creation data */
			);
	if(!hWindow)
		return 0;
	ShowWindow(hWindow, nFunsterStil);
	
	PIXELFORMATDESCRIPTOR pfd;
		int format;
		HDC hDC = GetDC(hWindow);
	
		ZeroMemory(&pfd, sizeof(pfd));
		pfd.nSize = sizeof(pfd);
		pfd.nVersion = 1;
		pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
		pfd.iPixelType = PFD_TYPE_RGBA;
		pfd.cColorBits = 24;
		pfd.cDepthBits = 16;
		pfd.iLayerType = PFD_MAIN_PLANE;
		format = ChoosePixelFormat(hDC, &pfd);
		SetPixelFormat(hDC, format, &pfd);
		HGLRC hRC = wglCreateContext(hDC);
		wglMakeCurrent(hDC, hRC);

	DWORD lastTime = GetTickCount();
	DWORD newTime, timeElapsed;
	while(true)
	{
		if(PeekMessage(&messages, NULL, 0, 0, PM_REMOVE))
		{
			if(messages.message == WM_QUIT)
				break;
			TranslateMessage(&messages);
	        DispatchMessage(&messages);
		}
		else
		{
			glClearColor(1.00f,0.00f,0.00f,1.00f);
			glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
			SwapBuffers(hDC);
		}
	}
	wglMakeCurrent(NULL, NULL);
	wglDeleteContext(hRC);
	ReleaseDC(hWindow, hDC);
	DestroyWindow(hWindow);
	return messages.wParam;
	
}

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
	{
	switch (message)
		{
		case WM_DESTROY:
			PostQuitMessage(0);
			break;
		case WM_SIZE:
			
			break;
		case WM_LBUTTONDOWN:
        case WM_RBUTTONDOWN:
            
            break;
		case WM_MOUSEMOVE:
            
            break;
        case WM_MOUSEWHEEL:
			
			break;
		case WM_COMMAND:
			switch(LOWORD(wParam))
			{
			default: break;
			}
			break;
		default:
			return DefWindowProc (hwnd, message, wParam, lParam);
		}
	return 0;
	}

